﻿using System.Collections.Generic;
using System.Diagnostics;

namespace CMWVS.Core
{
    public class Resolver
    {
        internal Resolver()
        {
            m_Resolver = new SortedDictionary<string, object>();
        }

        private SortedDictionary<string, object> m_Resolver;

        public void Register<T>(T obj) where T : class
        {
            if (null == obj)
            {
                Trace.Fail("invalid Object to register");
                return;
            }

            var t = typeof(T).FullName;
            if (!m_Resolver.ContainsKey(t))
            {
                m_Resolver.Add(t, obj);
            }
            else
            {
                m_Resolver[t] = obj;
            }
        }

        public T Get<T>()
        {
            var t = typeof(T).FullName;

            object obj;
            m_Resolver.TryGetValue(t, out obj);
            return (T)obj;
        }
    }
}